<template>
  <div class="divide-policy">
    <Card class="userCard">
      <div style="font-size: 16px">用户列表</div>
      <Divider></Divider>
      <!-- 查询行 -->
      <!-- <Row :gutter="50"> -->
      <Form :model="form">
        <Row gutter="30">
          <i-col span="6">
            <FormItem>
              <Select
                v-model="form.branchType"
                placeholder="渠道"
                clearable
                @on-change="branChTypeChange"
              >
                <Option key="1" value="1">个险</Option>
                <Option key="3" value="3">银保</Option>
                <!-- <Option
                  v-for="item in saleChannelList"
                  :key="item.key"
                  :value="item.key"
                >{{item.value}}</Option> -->
              </Select>
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <Cascader
                change-on-select
                :data="reagentOrganizationList"
                v-model="form.manageCom"
                @on-change="organizationChange1"
                placeholder="管理机构"
                clearable
              ></Cascader>
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <Select v-model="form.batchType" placeholder="分单类型" clearable>
                <Option value="2">全部</Option>
                <Option value="0">督导件</Option>
                <Option value="1">收费件</Option>
              </Select>
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <Select
                v-model="form.reAgentCode"
                placeholder="续期专员"
                clearable
              >
                <Option
                  v-for="item in reagentNameList"
                  :key="item.key"
                  :value="item.key"
                  >{{ item.value }}-{{ item.key }}</Option
                >
              </Select>
            </FormItem>
          </i-col>
        </Row>
        <Row gutter="30" v-if="channel">
          <i-col span="6">
            <FormItem>
              <Select
                v-model="form.agentGroup2"
                placeholder="代理人所属部"
                clearable
                filterable
                @on-change="queryGroup"
              >
                <Option
                  v-for="item in agentGroup1List"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <Select
                v-model="form.agentGroup1"
                placeholder="代理人所属组"
                clearable
                filterable
              >
                <Option
                  v-for="item in agentGroup2List"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
          </i-col>
        </Row>
        <Row gutter="30" v-if="department">
          <i-col span="6">
            <FormItem>
              <Select
                v-model="form.agentGroup2"
                placeholder="保单客户经理所属区"
                clearable
                @on-change="queryGroup"
              >
                <Option
                  v-for="item in agentGroup1List"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
          </i-col>
          <i-col span="6">
            <FormItem>
              <Select
                v-model="form.agentGroup1"
                placeholder="保单客户经理所属部"
                clearable
                filterable
              >
                <Option
                  v-for="item in agentGroup2List"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
          </i-col>
        </Row>
        <Row :gutter="50">
          <i-col span="8">
            <FormItem>
              <Button
                type="primary"
                @click="queryPolicy(1)"
                :loading="queryLoading"
                style="margin-right: 20px"
                >查询</Button
              >
              <Button @click="reset()" style="margin-right: 20px">重置</Button>
              <Button type="primary" @click="addPolicy">新增</Button>
            </FormItem>
          </i-col>
        </Row>
      </Form>
      <!-- </Row> -->
      <!-- 表格 -->
      <Table :columns="columns1" :data="data1">
        <template slot-scope="{ row }" slot="comName">
          {{ row.manageCom }}-{{ row.comName }}
        </template>
        <template slot-scope="{ row }" slot="agentGroup1Name">
          {{ row.wagentGroup1 }}-{{ row.agentGroup1Name }}
        </template>
        <template slot-scope="{ row }" slot="agentGroup2Name">
          {{ row.wagentGroup2 }}-{{ row.agentGroup2Name }}
        </template>
        <template slot-scope="{ row }" slot="reAgentCode">
          {{ row.reAgentCode }}-{{ row.reAgentName }}
        </template>

        <template slot-scope="{ row }" slot="reAgentGroup1Name">
          {{ row.reAgentGroup1 }}-{{ row.reAgentGroup1Name }}
        </template>
        <template slot-scope="{ row }" slot="reAgentGroup2Name">
          {{ row.reAgentGroup2 }}-{{ row.reAgentGroup2Name }}
        </template>
        <template slot-scope="{ row }" slot="operate">
          <Button type="primary" @click="editPolicy(row)">修改</Button>
        </template>
      </Table>

      <!-- 分页 -->
      <Row>
        <i-col span="24" style="text-align: right; margin-top: 20px">
          <Page
            :total="total"
            show-total
            show-sizer
            @on-change="pageChange"
            @on-page-size-change="pageSizeChange"
            :page-size-opts="pageSizeOptions"
            :current="pageIndex"
            :page-size="pageSize"
          />
        </i-col>
      </Row>
      <Button type="primary" @click="info" v-if="false"></Button>
    </Card>
    <Modal
      footer-hide="true"
      v-model="openModal"
      :mask-closable="false"
      @on-visible-change="modalVisibleChange"
      width="608"
    >
      <span
        slot="header"
        style="color: #fff; font-size: 16px"
        v-show="this.modalFlag == 'add'"
        >新增分单规则</span
      >
      <span
        slot="header"
        style="color: #fff; font-size: 16px"
        v-show="this.modalFlag != 'add'"
        >修改分单规则</span
      >
      <div style="width: 85%">
        <Form
          ref="addForm"
          :model="addForm"
          :rules="ruleValidate"
          :label-width="160"
        >
          <FormItem label="渠道" prop="branchType">
            <span class="assignSelect">
              <Select
                v-model="addForm.branchType"
                placeholder="销售渠道"
                clearable
                @on-change="branChTypeChange"
              >
                <Option key="1" value="1">个险</Option>
                <Option key="3" value="3">银保</Option>
              </Select>
            </span>
          </FormItem>
          <FormItem label="管理机构" prop="manageCom">
            <span class="assignSelect">
              <Cascader
                change-on-select
                :data="reagentOrganizationList"
                v-model="addForm.manageCom"
                @on-change="organizationChange"
                placeholder="管理机构"
                clearable
              ></Cascader>
            </span>
          </FormItem>
          <div v-if="channel">
            <FormItem label="保单代理人所属部" prop="agentGroup2">
              <Select
                v-model="addForm.agentGroup2"
                placeholder="保单代理人所属部"
                clearable
                @on-change="queryGroup"
                filterable
              >
                <Option
                  v-for="item in agentGroup1ListAdd"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
            <FormItem label="保单代理人所属组" prop="agentGroup1">
              <Select
                v-model="addForm.agentGroup1"
                placeholder="保单代理人所属组"
                clearable
                filterable
              >
                <Option
                  v-for="item in agentGroup2ListAdd"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
          </div>
          <div v-if="department">
            <FormItem label="保单客户经理所属区" prop="agentGroup2">
              <Select
                v-model="addForm.agentGroup2"
                placeholder="保单客户经理所属区"
                clearable
                filterable
                @on-change="queryGroup"
              >
                <Option
                  v-for="item in agentGroup1ListAdd"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
            <FormItem label="保单客户经理所属部" prop="agentGroup1">
              <Select
                v-model="addForm.agentGroup1"
                placeholder="保单客户经理所属部"
                clearable
                filterable
              >
                <Option
                  v-for="item in agentGroup2ListAdd"
                  :key="item.code"
                  :value="item.ncode"
                  >{{ item.code }}-{{ item.codeName }}</Option
                >
              </Select>
            </FormItem>
          </div>

          <FormItem label="分单类型" prop="batchType">
            <Select
              v-model="addForm.batchType"
              placeholder="分单类型"
              clearable
            >
              <Option value="2">全部</Option>
              <Option value="0">督导件</Option>
              <Option value="1">收费件</Option>
            </Select>
          </FormItem>
          <FormItem label="续期专员" prop="reAgentCode">
            <Select
              v-model="addForm.reAgentCode"
              placeholder="续期专员姓名"
              clearable
            >
              <Option
                v-for="item in reagentNameListAdd"
                :key="item.key"
                :value="item.key"
                >{{ item.value }}-{{ item.key }}</Option
              >
            </Select>
          </FormItem>
          <FormItem label="新人定义（月份）" prop="agentMonth">
            <!-- <Select v-model="addForm.reagentName" placeholder="续期专员姓名" clearable multiple>
                <Option
                  v-for="item in reagentNameListAdd"
                  :key="item.key"
                  :value="item.key"
                >{{item.value}}-{{item.key}}</Option>
              </Select> -->
            <i-input
              v-model="addForm.agentMonth"
              type="number"
              min="1"
              placeholder="请输入新人定义（月份）"
            />
            <!-- <i-input-number v-model="addForm.reagentName" min="0" max="100" placeholder="请输入新人定义(月份)" /> -->
            <!-- <Input :max="12" :min="1" v-model="addForm.agentMonth" placeholder="请输入新人定义(月份)" precision="0" style="width:100%"></Input> -->
          </FormItem>
        </Form>
        <Row>
          <i-col span="24" style="text-align: right">
            <Button type="primary" @click="submit()" :loading="submitLoading"
              >确定</Button
            >
            <Button style="margin-right: 5px" @click="cancel()">取消</Button>
          </i-col>
        </Row>
      </div>
    </Modal>
  </div>
</template>
<script>
import Cookies from "js-cookie";
export default {
  data() {
    const validateMonth = (rule, value, callback) => {
      let regstr = /^(?:1[0-2]|[1-9])$/;
      if (regstr.test(value)) {
        callback();
      } else {
        callback(new Error("请输入1-12的整数"));
      }
      callback();
    };
    return {
      saveGroup1: "",
      saveGroup2: "",
      savereName: "",
      modalFlag: "",
      // 当前页码
      pageIndex: 1,
      // 每页记录数量
      pageSize: 10,
      //  每页条数切换的配置
      pageSizeOptions: [5, 10, 15, 20],
      //  总数量
      total: 0,
      pageObj: null,
      form: {
        branchType: "",
        manageCom: "",
        batchType: "",
        reAgentCode: "",
        agentGroup1: "",
        agentGroup2: "",
      },
      addForm: {
        branchType: "1",
        manageCom: "",
        batchType: "2",
        reAgentCode: "",
        agentGroup1: "",
        agentGroup2: "",
        agentMonth: 3,
      },
      ruleValidate: {
        branchType: [{ required: true, message: "请选择", trigger: "blur" }],
        manageCom: [
          {
            required: true,
            type: "array",
            message: "请选择",
            trigger: "change",
          },
        ],
        batchType: [{ required: true, message: "请选择", trigger: "blur" }],
        reAgentCode: [{ required: true, message: "请选择", trigger: "blur" }],
        // agentGroup1: [
        //     { required: true, message: '请选择', trigger: 'blur' }
        // ],
        agentGroup2: [{ required: true, message: "请选择", trigger: "blur" }],
        agentMonth: [
          { validator: validateMonth, trigger: "change" },
          // { type: 'number', message: '请输入', trigger: 'change' }
        ],
      },
      //   stateList: [
      //     { key: '0', value: '活跃' },
      //     { key: '1', value: '不活跃' },
      //     { key: '2', value: '全部' }
      //   ],

      // 表格数据
      columns1: [
        {
          title: "管理机构",
          slot: "comName",
          //   slot: 'indexNo',
          align: "center",
          width: "400",
        },
        {
          title: "分单类型",
          key: "batchType",
          align: "center",
          width: "120",
        },
        {
          title: "代理人所属部",
          slot: "agentGroup2Name",
          align: "center",
          width: "200",
        },
        {
          title: "代理人所属组",
          slot: "agentGroup1Name",
          align: "center",
          width: "200",
        },
        {
          title: "续期专员",
          slot: "reAgentCode",
          align: "center",
          width: "200",
        },
        {
          title: "续期专员所属部",
          slot: "reAgentGroup2Name",
          align: "center",
          width: "200",
        },
        {
          title: "续期专员所属组",
          slot: "reAgentGroup1Name",
          align: "center",
          width: "200",
        },
        {
          title: "新人定义",
          key: "agentMonth",
          align: "center",
          width: "120",
        },

        {
          title: "操作",
          key: "operate",
          slot: "operate",
          fixed: "right",
          width: "100",
        },
      ],
      data1: [],
      queryLoading: false,
      openModal: false,
      saleChannelList: [],
      reagentOrganizationList: [],
      reagentNameList: [],
      reagentNameListAdd: [],
      agentGroup1List: [],
      agentGroup1ListAdd: [],
      agentGroup2List: [],
      agentGroup2ListAdd: [],
      submitLoading: false,
      //   // 机构列表
      //   organizationList: {},
      //   // 职级列表
      //   levelList: {},
      //   // 开关状态
      channel: true,
      department: false,
    };
  },
  watch: {
    "form.manageCom"() {
      if (!this.form.manageCom) {
        this.reagentNameList = [];
        this.agentGroup1List = [];
        this.agentGroup2List = [];
        this.form.reAgentCode = "";
        this.form.agentGroup1 = "";
        this.form.agentGroup2 = "";
      }
    },
    "form.agentGroup2"() {
      if (!this.form.agentGroup2) {
        this.agentGroup2List = [];
        this.form.agentGroup1 = "";
      }
    },
    "addForm.manageCom"() {
      if (!this.addForm.manageCom) {
        this.reagentNameListAdd = [];
        this.agentGroup1ListAdd = [];
        this.agentGroup2ListAdd = [];
        this.addForm.reAgentCode = "";
        this.addForm.agentGroup1 = "";
        this.addForm.agentGroup2 = "";
      }
    },
    "addForm.agentGroup2"() {
      if (!this.addForm.agentGroup2) {
        this.agentGroup2ListAdd = [];
        this.addForm.agentGroup1 = "";
      }
    },
  },
  methods: {
    info(tip) {
      this.$Message.warning(tip);
    },
    //
    queryPolicy(flag) {
      if (flag) {
        this.pageIndex = flag;
      }
      this.queryLoading = true;
      let obj = {
        branchType: this.form.branchType || null,
        manageCom: this.form.manageCom[this.form.manageCom.length - 1] || null,
        batchType:
          this.form.batchType === "0" ? "0" : this.form.batchType || null,
        reAgentCode: this.form.reAgentCode || null,
        agentGroup1: this.form.agentGroup1 || null,
        agentGroup2: this.form.agentGroup2 || null,
      };
      obj.index = this.pageIndex;
      obj.pageSize = this.pageSize;
      this.api
        .queryReRuleAllInfo(obj)
        .then((res) => {
          if (res.code == 200 && res.data) {
            this.queryLoading = false;
            this.data1 = res.data.records;
            this.total = res.data.total;
          } else {
            this.total = 0;
            this.data1 = [];
            this.queryLoading = false;
          }
        })
        .catch((e) => {
          this.data1 = [];
          this.queryLoading = false;
          this.$Message.error("请求异常");
        });
    },
    //保存
    submit() {
      // addForm
      this.$refs["addForm"].validate((valid) => {
        if (valid) {
          // this.$Message.success('Success!');
          this.submitLoading = true;
          // let par = this.addForm
          let par = {
            branchType: this.addForm.branchType,
            manageCom:
              this.addForm.manageCom[this.addForm.manageCom.length - 1],
            batchType: this.addForm.batchType,
            reAgentCode: this.addForm.reAgentCode,
            agentGroup1: this.addForm.agentGroup1,
            agentGroup2: this.addForm.agentGroup2,
            agentMonth: this.addForm.agentMonth,
            operator: sessionStorage.getItem("useragentcode"),
            // serialNo: this.addForm.serialNo || '',
          };
          if (this.modalFlag == "add") {
            this.api
              .addReRule(par)
              .then((res) => {
                if (res.code == 200 && res.data) {
                  this.submitLoading = false;
                  this.$Message.info(res.msg);
                  // this.$refs['addForm'].resetFields();
                  this.openModal = false;
                  this.queryPolicy();
                } else {
                  // this.data1 = []
                  this.submitLoading = false;
                  // this.$refs['addForm'].resetFields();
                  this.$Message.info(res.msg);
                  this.openModal = false;
                }
              })
              .catch((e) => {
                this.data1 = [];
                this.submitLoading = false;
                this.$Message.error("请求异常");
              });
          } else {
            (par.serialNo = this.addForm.serialNo || ""),
              this.api
                .updateReRule(par)
                .then((res) => {
                  this.submitLoading = false;
                  this.$Message.info(res);
                  // this.$refs['addForm'].resetFields();
                  this.openModal = false;
                  this.queryPolicy();
                  // if (res.code == 200 && res.data) {
                  //     this.submitLoading = false
                  //     this.$Message.success(res.data);
                  // } else {
                  //     this.submitLoading = false
                  // }
                })
                .catch((e) => {
                  this.submitLoading = false;
                  this.$Message.error("请求异常");
                  // this.$refs['addForm'].resetFields();
                  this.openModal = false;
                });
          }
        } else {
          return;
          // this.$Message.error('Fail!');
        }
      });
    },
    pageChange(e) {
      this.pageIndex = e;
      this.queryPolicy();
    },
    pageSizeChange(e) {
      this.pageSize = e;
      this.queryPolicy();
    },
    cancel() {
      //弹窗数据初始化
      this.openModal = false;
    },
    addPolicy() {
      Object.assign(this.$data.addForm,this.$options.data().addForm)
      this.modalFlag = "add";
      this.openModal = true;
      this.channel = true;
      this.department = false;
      // this.addForm.branchType = "1",
      // this.addForm.agentMonth = 3
    },
    // 修改数据回
    editPolicy(row) {
      this.modalFlag = "edit";
      this.openModal = true;
      let data = JSON.parse(JSON.stringify(row));
      let arr = [];
      this.reagentOrganizationList.forEach((one) => {
        if (one.value == row.manageCom) {
          arr.push(one.value);
        } else if (one.children) {
          one.children.forEach((two) => {
            if (two.value == row.manageCom) {
              arr.push(one.value, two.value);
            } else if (two.children) {
              two.children.forEach((three) => {
                if (three.value == row.manageCom) {
                  arr.push(one.value, two.value, three.value);
                } else if (three.children) {
                  three.children.forEach((four) => {
                    if (four.value == row.manageCom) {
                      arr.push(one.value, two.value, three.value, four.value);
                    }
                  });
                }
              });
            }
          });
        }
      });
      console.log(arr, "arr");
      // row.manageCom = arr;
      if(row.branchType === "个险"){
        this.channel = true;
        this.department = false;
      }else{
        this.channel = false;
        this.department = true;
      }
      this.addForm = {
        branchType: row.branchType == "个险" ? "1" : "3",
        manageCom: row.manageCom || [],
        batchType:
          row.batchType === "督导件"
            ? "0"
            : row.batchType === "收费件"
            ? "1"
            : row.batchType === "全部"
            ? "2"
            : "",
        reAgentCode: row.reAgentCode || "",
        agentGroup1: row.agentGroup1 || "",
        agentGroup2: row.agentGroup2 || "",
        agentMonth: row.agentMonth || "3",
        serialNo: row.serialNo || "",
        manageCom :arr
      };
      (this.saveGroup1 = row.agentGroup1 || ""),
        (this.saveGroup2 = row.agentGroup2 || ""),
        (this.savereName = row.reAgentCode || ""),
        this.organizationChange(this.addForm.manageCom);

    },
    modalVisibleChange(flag) {
      // console.log("addForm",this.addForm)
      // console.log(flag)
      if (flag) {
        // this.openModal = true
      } else {
        this.$refs["addForm"].resetFields();
        //    this.openModal = false
      }
    },
    // 进入页面初始化
    initialize() {
      //   this.userQuery(1)
      this.api.remanagecomList().then((res) => {
        if (res.code == 200 && res.data != null) {
          let arr = [];
          arr.push(res.data);
          arr.forEach((one) => {
            one.value = one.comcode;
            one.label = one.comcode + "-" + one.name;
            one.children = one.chilDren || [];
            if (one.children) {
              one.chilDren.forEach((two) => {
                two.value = two.comcode;
                two.label = two.comcode + "-" + two.name;
                two.children = two.chilDren || [];
                if (two.children) {
                  two.children.forEach((three) => {
                    three.value = three.comcode;
                    three.label = three.comcode + "-" + three.name;
                    three.children = three.chilDren || [];
                    if (three.children) {
                      three.children.forEach((four) => {
                        four.value = four.comcode;
                        four.label = four.comcode + "-" + four.name;
                        four.children = four.chilDren || [];
                      });
                    }
                  });
                }
              });
            }
          });
          console.log(arr);
          this.reagentOrganizationList = arr;
        } else {
          this.reagentOrganizationList = [];
        }
      });
      this.api.professionalList().then((res) => {
        if (res.code == 200 && res.data != null) {
          //   if (res.data.planListVOS) {
          //     this.workStatusList = res.data.planListVOS;
          //   }
          if (res.data.salechnlListVOS) {
            let list = res.data.salechnlListVOS;
            list.map((item) => {
              item.key = Number(item.key).toString();
            });
            this.saleChannelList = list;
          }
          // if (res.data.listKeyValueVOS) {
          //   this.reagentOrganizationList = res.data.listKeyValueVOS;
          // }
          //   if (res.data.payintvVOS) {
          //     this.payList = res.data.payintvVOS;
          //   }
          //   if (res.data.contstateListVOS) {
          //     this.applyStatusList = res.data.contstateListVOS;
          //   }
        } else {
          // this.reagentorganizationList = [];
          this.saleChannelList = [];
          this.workStatusList = [];
          this.payList = [];
          this.applyStatusList = [];
        }
      });
    },
    // 根据管理机构查询续期专员
    organizationChange(value) {
      if (!value) {
        if (!this.openModal) {
          this.reagentNameList = [];
        } else {
          this.reagentNameListAdd = [];
        }
      } else {
        $.ajax("scrm-gateway/scrm-uer/api/List/sekectreangencode/" + value[value.length - 1], {
          method: "get",
          contentType: "application/json;charset=utf-8",
          headers: {
            Authorization: sessionStorage.getItem("credentials"),
          },
          success: (res) => {
            if (res.code == 200 && res.data != null) {
              //   this.reagentNameList = res.data;
              if (!this.openModal) {
                this.reagentNameList = res.data;
              } else {
                this.reagentNameListAdd = res.data;
                if (this.savereName) {
                  this.addForm.reAgentCode = this.savereName;
                  this.savereName = "";
                }
              }
            } else {
              if (!this.openModal) {
                this.reagentNameList = [];
              } else {
                this.reagentNameListAdd = [];
              }
            }
          },
          error: (res) => {
            this.$Message.error(res.msg);
          },
        });
        console.log(this.form.branchType,"1");
        let queryObj = {
            codeType: "1",
            code: value[value.length - 1],
            // branchType: this.form.branchType || this.addForm.branchType,
            branchType: (this.modalFlag === "add" || this.modalFlag === "edit") ? this.addForm.branchType : this.form.branchType,
          }
          if(this.modalFlag === "edit"){
            queryObj.manageCom = this.addForm.manageCom[this.addForm.manageCom.length - 1] || "",//机构
            queryObj.codeType2 = this.addForm.agentGroup2 || ""//部
          }
        this.api
          .queryPartGroup(queryObj)
          .then((res) => {
            console.log(res, "resxuqizhuanyuan ");
            if (res) {
              if (!this.openModal) {
                this.agentGroup1List = res;
              } else {
                this.agentGroup1ListAdd = res;
                if (this.saveGroup2) {
                  this.addForm.agentGroup1 = this.saveGroup1;
                  this.saveGroup2 = "";
                  this.queryGroup(this.addForm.agentGroup2);
                }
              }
            } else {
              if (!this.openModal) {
                this.agentGroup1List = [];
              } else {
                this.agentGroup1ListAdd = [];
              }
            }
          });
      }
    },
    //查询组
    queryGroup(value) {
      console.log(value, this.form.branchType, "查询");
      if(!value){
        return
      }
      let queryObj = {
          codeType: "2",
          code: value,
          // branchType: this.modalFlag === "add" ? this.addForm.branchType : this.form.branchType,
          branchType: (this.modalFlag === "add" || this.modalFlag === "edit") ? this.addForm.branchType : this.form.branchType,
          
        }
          if(this.modalFlag === "edit"){
            queryObj.manageCom = this.addForm.manageCom[this.addForm.manageCom.length - 1] || "",//机构
            queryObj.codeType2 = this.addForm.agentGroup2 || ""//部
            queryObj.codeType3 = this.addForm.agentGroup1|| ""//组
          }
      this.api
        .queryPartGroup(queryObj)
        .then((res) => {
          console.log(res, "res");
          if (res) {
            if (!this.openModal) {
              this.agentGroup2List = res;
            } else {
              this.agentGroup2ListAdd = res;
              if (this.saveGroup2) {
                this.addForm.agentGroup2 = this.saveGroup2;
                this.saveGroup2 = "";
              }
            }
          } else {
            if (!this.openModal) {
              this.agentGroup2List = [];
            } else {
              this.agentGroup2ListAdd = [];
            }
          }
        });
    },
    // 根据管理机构查询续期专员--全量数据
    organizationChange1(value) {
      if (!value) {
        this.reagentNameList = [];
      } else {
        $.ajax("scrm-gateway/scrm-uer/api/List/sekectreangencode/" + value[value.length - 1], {
          method: "get",
          contentType: "application/json;charset=utf-8",
          headers: {
            Authorization: sessionStorage.getItem("credentials"),
          },
          success: (res) => {
            if (res.code == 200 && res.data != null) {
                this.reagentNameList = res.data;
            } else {
              this.reagentNameList = [];
            }
          },
          error: (res) => {
            this.$Message.error(res.msg);
          },
        });
        console.log(this.form.branchType,"1");
        let queryObj = {
            codeType: "1",
            code: value[value.length - 1],
            // branchType: this.form.branchType || this.addForm.branchType,
            branchType:this.form.branchType,
          }
        this.api
          .queryPartGroups(queryObj)
          .then((res) => {
            if (res) {
              this.agentGroup1List = res;
            } else {
              this.agentGroup1List = [];
            }
          });
      }
    },
    //查询组
    queryGroup1(value) {
      console.log(value, this.form.branchType, "查询");
      if(!value){
        return
      }
      let queryObj = {
          codeType: "2",
          code: value,
          // branchType: this.modalFlag === "add" ? this.addForm.branchType : this.form.branchType,
          branchType:this.form.branchType,
        }
      this.api
        .queryPartGroups(queryObj)
        .then((res) => {
          console.log(res, "res");
          if (res) {
            this.agentGroup2List = res;
          } else {
            this.agentGroup2List = [];
          }
        });
    },
    reset() {
      this.form = {
        branchType: "",
        manageCom: "",
        batchType: "",
        reAgentCode: "",
        agentGroup1: "",
        agentGroup2: "",
      };
      this.reagentNameList = [];
    },

    // 修改信息确认
    resetPswSubmit() {
      this.$refs.resetPswForm.validate((valid) => {
        if (valid) {
        }
      });
    },
    saveUpdate() {
      this.api.resetPwd(this.updateObj).then((res) => {
        if (res.code == 200) {
        } else {
          this.$Message.info("工号已存在");
        }
      });
    },
    // 2376区部展示
    branChTypeChange(value) {
      console.log(value, "value");
      this.addForm.manageCom = "";
      this.form.manageCom = "";
      if (value === "3") {
        this.channel = false;
        this.department = true;
      } else {
        this.channel = true;
        this.department = false;
      }
    },
  },
  mounted() {
    // 进入页面初始化
    this.initialize();
    // this.organizationChange();
    // this.organizationChange(this.form.reagentOrganization);
    this.queryPolicy();
  },
};
</script>
<style lang="less">
.ivu-modal-header {
  background-color: #2d8cf0 !important;
}
.divide-policy {
  .ivu-input-number {
    width: 100% !important;
  }
}

.divide-policy .ivu-input-number {
  width: 100%;
}
</style>

<style scoped lang="less">
@import "./user";
.ivu-modal-header {
  background-color: #2d8cf0;
}
.ivu-modal-close .ivu-icon-ios-close {
  color: #fff;
}

.stopClass > .ivu-modal {
  top: 0;
  left: 25px;
}
.addClass > .ivu-modal {
  top: 140px;
}
.updateClass > .ivu-modal {
  top: 140px;
}
.btngroup {
  width: 100%;
  display: flex;
  justify-content: center;
}
.btngroup .ivu-col-span-8 {
  display: inline-block;
  width: 100px;
}
</style>

